﻿using Wlmy.Ids4.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Wlmy.Ids4.Common;

namespace Wlmy.Ids4.Services
{
    public class BaseServices<T>: IBaseServices<T>
    {
        private readonly IBaseRepository<T> _baseRepository;
        protected readonly IMapper mapper = StaticInfo.GetService<IMapper>();
        public BaseServices(IBaseRepository<T> baseRepository)
        {
            _baseRepository = baseRepository;
        }
        public async Task AddAsync(T entity)
        {
            await _baseRepository.AddAsync(entity);
        }
        public async Task SaveChangesAsync()
        {
            await _baseRepository.SaveChangesAsync();
        }
        public  void SaveChanges()
        {
            _baseRepository.SaveChanges();
        }
        public async Task AddRangeAsync(List<T> entities)
        {
            await _baseRepository.AddRangeAsync(entities);
        }

        public async Task<bool> AnyAsync(Expression<Func<T, bool>> expression)
        {
            return await _baseRepository.AnyAsync(expression);
        }

        public async Task DeleteAsync(T entity)
        {
            await _baseRepository.DeleteAsync(entity);
        }
        public async Task DeleteAsync(int id)
        {
            await _baseRepository.DeleteAsync(id);
        }

        public void DeleteRange(List<T> entities)
        {
            _baseRepository.DeleteRange(entities);
        }

        public IQueryable<T> GetALL()
        {
            return _baseRepository.GetALL();
        }

        public async Task<T> GetByIdAsync(int id)
        {
            return await _baseRepository.GetByIdAsync(id);
        }

        public async Task<T> GetByIdIncludeNavAsync(int id)
        {
            return await _baseRepository.GetByIdIncludeNavAsync(id);
        }

        public async Task<T> SingleAsync(Expression<Func<T, bool>> expression)
        {
            return await _baseRepository.SingleAsync(expression);
        }

        public async Task<T> SingleIncludeNavAsync(Expression<Func<T, bool>> expression)
        {
            return await _baseRepository.SingleIncludeNavAsync(expression);
        }

        public async Task UpdateAsync(T entity)
        {
            await _baseRepository.UpdateAsync(entity);
        }

        public void UpdateRange(List<T> entities)
        {
            _baseRepository.UpdateRange(entities);
        }

        public IQueryable<T> Where(Expression<Func<T, bool>> expression)
        {
            return _baseRepository.Where(expression);
        }
    }
}
